﻿using System;
using System.Configuration;

namespace Comsenz.Base.Configs
{
    /// <summary>
    /// 链接配置集
    /// </summary>
    /// <author>Chiron</author>
    [ConfigurationCollection(typeof(ConnectConfig))]
    public class ConnectCollection : ConfigurationElementCollection
    {
        #region ConfigurationElementCollection
        protected override ConfigurationElement CreateNewElement()
        {
            return new ConnectConfig();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ConnectConfig)element).Name;
        }
        #endregion ConfigurationElementCollection

        #region Ctors
        public ConnectCollection()
            : base(StringComparer.OrdinalIgnoreCase)
        {

        }
        #endregion

        #region Methods
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="connect"></param>
        public void Add(ConnectConfig connect)
        {
            if (connect != null)
            {
                this.BaseAdd(connect);
            }
        }

        /// <summary>
        /// 清空
        /// </summary>
        public void Clear()
        {
            base.BaseClear();
        }

        /// <summary>
        /// 移除
        /// </summary>
        /// <param name="name"></param>
        public void Remove(string name)
        {
            base.BaseRemove(name);
        }
        #endregion Methods

        #region Indexers
        public ConnectConfig this[int index]
        {
            get
            {
                return base.BaseGet(index) as ConnectConfig;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }
        public new ConnectConfig this[string key]
        {
            get
            {
                return base.BaseGet(key) as ConnectConfig;
            }
        }
        #endregion Indexers
    }
}
